#include <lobi/image.h>

#include "tga.h"
#include "pcx.h"

#include <assert.h>
#include <stdlib.h>

/* want_rgba=1 -> swap tga's native bgr(a) to rgb(a). want_rbga=0 means we swap ourselves or use GL_RGBA_EXT etc */
int image_sread_tga(const char* data,unsigned len,struct image_t* destination_image, int want_rgba);
int image_sread_dds(const char* data,unsigned len,struct image_t* destination_image);

int image_sread(const char* data,unsigned len, int type, struct image_t* destination_image)
{
	assert(destination_image);

	switch(type)
	{
		case IMAGE_TYPE_TGA:
			return image_sread_tga(data,len,destination_image, 1/* swap to rgb(a) */);
		case IMAGE_TYPE_PCX:
			return image_sread_pcx(data,len,destination_image);
		case IMAGE_TYPE_DDS:
			return image_sread_dds(data,len,destination_image);

		default: 
			return 1;
	}
	return 0;
}

void image_init(struct image_t* image)
{
	image->height = image->width = 0;
	image->bytes_per_pixel = 0;
	image->num_channels = image->num_mipmaps = 0;
	image->pixels = 0;
}
void image_free(struct image_t* image)
{
	assert(image);

	if (image->pixels) { free(image->pixels); image->pixels=0; }
}


/* once implemented these will go to their own files */
int image_sread_dds(const char* data,unsigned len,struct image_t* destination_image)
{
	return 1;
}
